package com.crm.finance.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.model.BizProject;
import com.crm.model.ConsultInfoManage;
import com.crm.model.ConsultInfoManagePay;
import com.crm.model.entity.ConsultInfoManagePayEntity;
import com.crm.service.BizProjectService;
import com.crm.service.ConsultInfoManagePayService;
import com.crm.service.ConsultInfoManageService;
import com.crm.util.ResponseUtil;
import com.github.pagehelper.Page;

/**
 * @author 
 *
 * 集团财务收入明细
 *
 */
@Controller
@RequestMapping("/financeGroupIncome")
public class FinanceGroupIncomeController {
	
	@Autowired
	private ConsultInfoManagePayService  consultPayService;
	
	@Autowired
	private ConsultInfoManageService consultService;
	
	@Autowired
	private BizProjectService projectService;
	@RequestMapping("/index")
	public String index(){
		
		return "financeCenter/groupFinance";
	}
	
	@RequestMapping("/loadPayDeatil")
	public void loadPayDeatil(HttpServletResponse response,HttpServletRequest request,Page<ConsultInfoManagePayEntity> page,ConsultInfoManagePayEntity consultInfoManagePayEntity){
		Page<ConsultInfoManagePayEntity> payDeatilList =(Page<ConsultInfoManagePayEntity>)consultPayService.selectPayDetail(page,consultInfoManagePayEntity); 
		ResponseUtil.resultPage(response, request, payDeatilList);
	}
	
	@RequestMapping("/loadPaySum")
	@ResponseBody
	public List<Map<String,Object>> loadPaySum(ConsultInfoManagePayEntity consultInfoManage){
		List<Map<String,Object>> retMap = consultPayService.selectKindOfPayCount(consultInfoManage);
		return retMap;
		
	}
	@RequestMapping("getStuPayDeatil/{infoManageId}")
	@ResponseBody
	public Map<String,Object> getPersonPayDeatil(@PathVariable("infoManageId")String infoManageId){
		Map<String,Object> retMap = new HashMap<>();
		ConsultInfoManage consultInfo =consultService.selectByPrimaryKey2(infoManageId);;
		List<ConsultInfoManagePay> payInfoData= consultPayService.getPayDetailByInfoId(infoManageId);
		BizProject project =consultInfo==null?null:projectService.selectByPrimaryKey(consultInfo.getProjectId());
		retMap.put("consultInfo", consultInfo);
		retMap.put("payInfoData", payInfoData);
		retMap.put("project", project);
		return retMap;
	}

}
